package com.liang.set;

import java.util.TreeSet;

public class ComparatorDemo {
    public static void main(String[] args) {
//        Set<Person> arr = new TreeSet<>(new Comparator<Person>() {
//            @Override
//            public int compare(Person o1, Person o2) {
//                int result = o1.getAge()-o2.getAge();
//                return result == 0 ? o1.getName().compareTo(o2.getName()):result;
//            }
//        });

        TreeSet<Person> arr = new TreeSet<>((Person o1,Person o2)->{
            int result = o1.getAge()-o2.getAge();
            return result ==0? o1.getName().compareTo(o2.getName()):result;
        });

        Person p1 = new Person("zhangsan", 22);
        Person p2 = new Person("lisi", 24);
        Person p3 = new Person("wangwu", 23);
        Person p4 = new Person("zhaoliu", 22);

        arr.add(p1);
        arr.add(p2);
        arr.add(p3);
        arr.add(p4);

        System.out.println(arr);

    }
}
